package com.cqtczh.qhd.driver.acticity;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javabeen.CarTeamInfoBeen;

import httptools.HttpJsonTool;

import com.google.gson.reflect.TypeToken;
import com.cqtczh.qhd.driver.R;
import com.cqtczh.qhd.driver.model.CargoInfo;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

/**
 * @author 作者 E-mail:
 * @date 创建时间：2015-5-30 下午7:00:14
 * @version 1.0
 * @parameter
 * @since
 * @return
 */
public class delet_carteam_activity extends Activity {
	private HttpJsonTool httpJsonTool;
	
	private  List<CarTeamInfoBeen> carTeamInfo=new ArrayList<CarTeamInfoBeen>();
	private Handler handler;
	private int CarLeaderID,carteamId;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.delet_carteam_activity_xml);
		Bundle bundle = getIntent().getExtras();
		httpJsonTool = new HttpJsonTool(this);
	
		carTeamInfo = new ArrayList<CarTeamInfoBeen>();
		if (bundle != null) {
			//车队ID
			carteamId=	bundle.getInt("carteamId");
			Log.v("carteamId", ""+carteamId);
			GetCarTeamInfo(carteamId);
			//车队队长ID
		//	CarLeaderID=bundle.getInt("CarLeaderID");
		}else {
			Log.v("", "为空");
		}
		
	
		
	}

	private void IniView(){
		if (!carTeamInfo.isEmpty()) {
		TextView textView1=	(TextView) findViewById(R.id.textView1);
		TextView textView2=	(TextView) findViewById(R.id.textView2);
		TextView textView3=	(TextView) findViewById(R.id.textView3);
		TextView textView4=	(TextView) findViewById(R.id.textView4);
		TextView textView5=	(TextView) findViewById(R.id.textView5);
		TextView textView6=	(TextView) findViewById(R.id.textView6);
		TextView textView7=	(TextView) findViewById(R.id.textView7);
		textView1.setText("车队名字："+carTeamInfo.get(0).getMotorcadename());
		textView2.setText("车队电话号码：" +carTeamInfo.get(0).getPhone());
		textView3.setText("车队描述："+carTeamInfo.get(0).getMotorcadedescription());
		textView4.setText("队长名字：" +carTeamInfo.get(0).getCarownername());
		textView5.setText("队长电话号码："+carTeamInfo.get(0).getPhone());
		textView6.setText("队长的QQ："+carTeamInfo.get(0).getQq());
		textView7.setText("队长的微信：" +carTeamInfo.get(0).getWechatid());
		//textView1.setText("车队名字："+carTeamInfo.get(0).getMotorcadeid());
		Button button=(Button) findViewById(R.id.button1);
		button.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				UpDriveridea(carteamId,"yes");
			}
		});

		Button button2=(Button)findViewById(R.id.button2);
		button2.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				UpDriveridea(carteamId,"no");
			}
		});
		}
	}

	private void UpDriveridea(int carteamId,String idea) {
		// httpJsonTool.
		Map<String, Object> map=new HashMap<String, Object>();
		//车队ID
		map.put("motorcadeid", carteamId+"");

		//被邀请司机的id  userid
		map.put("userId", "3");
		//车队队长的ID
		map.put("carownerid", carTeamInfo.get(0).getCarownerid());
		//司机同意或者不同意
		map.put("state", idea);
		httpJsonTool.StartWork(map,"http://192.168.1.111:8080/cqtczh/moduls/fleets/receive.do", null,null);
	}

	private void GetCarTeamInfo(int carteamId) {
		
		Map<String, Object> map=new HashMap<String, Object>();
		map.put("motorcadeid", carteamId+"");
		httpJsonTool.SetOnLister(new Handler(){
			@SuppressWarnings("unchecked")
			@Override
			public void handleMessage(Message msg) {
				// TODO Auto-generated method stub
				super.handleMessage(msg);
				if (msg.what==1) {
					carTeamInfo=(List<CarTeamInfoBeen>) msg.obj;
					IniView();
				}
			}
		});
		Type	typ = new TypeToken<List<CarTeamInfoBeen>>() {}.getType();
		if (typ==null) {
			Log.v("type", "GetCarTeamInfo-->是空");
		}
		httpJsonTool.StartWork(map,"http://192.168.1.111:8080/cqtczh/moduls/fleets/info.do", typ,null);
	}
}
